package com.zl.util;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @author lei
 * 
 */
public class Page<T> {
	private int currentPage;
	private int pageSize;
	private int sizeOption[];
	private int beginIndex;
	private int endIndex;
	private List<T> recordList;
	private int total;
	private int pageCount;
	private String pagebar[];

	public Page(int currentPage, int pageSize, List<T> recordList, int total) {
		this.currentPage = currentPage;
		this.pageSize = pageSize;
		this.recordList = recordList;
		this.total = total;
		this.sizeOption = new int[] { 10, 15, 20, 50 };
		pageCount = (total + pageSize - 1) / pageSize;
		if (pageCount <= 5) {
			beginIndex = 1;
			endIndex = pageCount;
		} else {
			beginIndex = currentPage - 2;
			endIndex = currentPage + 2;
			if (beginIndex < 1) {
				beginIndex = 1;
				endIndex = 5;
			} else if (endIndex > pageCount) {
				beginIndex = pageCount - 4;
				endIndex = pageCount;
			}
		}
		String pnums = "";
		if (endIndex != 0) {
			for (int i = beginIndex; i <= endIndex; i++)
				pnums += (i + ",");
			pagebar = pnums.substring(0, pnums.length() - 1).split(",");
		} else {
			pagebar = new String[] {};
		}
	}

	public String[] getPagebar() {
		return pagebar;
	}

	public void setPagebar(String[] pagebar) {
		this.pagebar = pagebar;
	}

	public int[] getSizeOption() {
		return sizeOption;
	}

	public void setSizeOption(int[] sizeOption) {
		this.sizeOption = sizeOption;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getBeginIndex() {
		return beginIndex;
	}

	public void setBeginIndex(int beginIndex) {
		this.beginIndex = beginIndex;
	}

	public int getEndIndex() {
		return endIndex;
	}

	public void setEndIndex(int endIndex) {
		this.endIndex = endIndex;
	}

	public List<T> getRecordList() {
		return recordList;
	}

	public void setRecordList(List<T> recordList) {
		this.recordList = recordList;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	@Override
	public String toString() {
		return "PageBean [currentPage=" + currentPage + ", pageSize="
				+ pageSize + ", beginIndex=" + beginIndex + ", endIndex="
				+ endIndex + ", recordList=" + recordList + ", total=" + total
				+ ", pageCount=" + pageCount + "]";
	}

}
